﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using XZen.Blogger;
using System.Diagnostics;

namespace BlobTest
{
    [TestClass]
    public class XzenClientTest
    {
        string userName = "rijusmit";
        string password = "$Rijusmit2014";
        string subscription = "blogger";
        string contentUri = "http://localhost";
        BlogService service;
        public XzenClientTest()
        {
            service = new BlogService(userName, subscription);
            Connect();
        }
        public void Connect()
        {
            string data = service.Login(userName, password, contentUri);
            Debug.WriteLine(data);
        }

        [TestMethod]
        public void CreateBlog()
        {
            Blog newBlog = new Blog()
            {
                Body = "Here is new blog",
                Category = "Generic",
                Name = "RijuRaja",
                Title = "Here I Come as Raja",
                User = "rijusmit"
            };

            var id = BlogService.Instance.CreateBlog(newBlog);
            Debug.WriteLine(id);
        }
        [TestMethod]
        public void GetBlog()
        {
            Blog newBlog = new Blog()
            {
                Body = "Here is new blog",
                Category = "Generic",
                Name = "RijuRaja",
                Title = "Here I Come as Raja",
                User = "rijusmit"
            };

            var blog = BlogService.Instance.GetBlogByName(newBlog.Name);

            Debug.WriteLine(blog.Title);
        }
        [TestMethod]
        public void CreatePost()
        {
            Blog newBlog = new Blog()
            {
                Body = "Here is new blog",
                Category = "Generic",
                Name = "RijuRaja",
                Title = "Here I Come as Raja",
                User = "rijusmit"
            };


            var blog = BlogService.Instance.GetBlogByName(newBlog.Name);
            Posting post = new Posting()
                {
                    BlogID = blog.ID,
                    Body = "Here I can write anything",
                    Category = "Generic",
                    Name = "First Post",
                    Title = "Here We do not have manythings",
                    User = "rijusmit"
                };
            var pid = BlogService.Instance.CreatePosting(blog.ToID(), post);

            Debug.WriteLine(pid);
        }
        [TestMethod]
        public void CreateAnotherPost()
        {
            Blog newBlog = new Blog()
            {
                Body = "Here is new blog",
                Category = "Generic",
                Name = "RijuRaja",
                Title = "Here I Come as Raja",
                User = "rijusmit"
            };


            var blog = BlogService.Instance.GetBlogByName(newBlog.Name);
            Posting post = new Posting()
            {
                BlogID = blog.ID,
                Body = "Here I can write anything, and more things here",
                Category = "Generic",
                Name = "Second Post",
                Title = "Here We do not have manythings, yes we can do it",
                User = "rijusmit"
            };
            var pid = BlogService.Instance.CreatePosting(blog.ToID(), post);

            Debug.WriteLine(pid);
        }
    }
}
